package com.lmf.ssm.bean;

import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 创建一个类作为通用返回
 */
public class Msg {
    //请求成功，返回代码100；请求失败，返回代码200
    private Integer core;
    //提示信息
    private String msg;
    //用户返回给浏览器的数据
    private Map<String,Object> map=new HashMap<>();

    public Integer getCore() {
        return core;
    }

    public void setCore(Integer core) {
        this.core = core;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public Msg() {
    }

    public Msg(Integer core, String msg, Map<String, Object> map) {
        this.core = core;
        this.msg = msg;
        this.map = map;
    }

    public static Msg success(){
        Msg msg = new Msg();
        msg.setCore(100);
        msg.setMsg("处理成功！");
        return msg;
    }
    public static Msg fail(){
        Msg msg = new Msg();
        msg.setCore(200);
        msg.setMsg("处理失败！");
        return msg;
    }

    public Msg add(String key,Object value){
        Object put = this.getMap().put(key, value);
        return this;
    }

//    public Msg add(String key, PageInfo<Employee> value) {
//        //方式一：
////        HashMap<String, Object> map = new HashMap<>();
////        map.put(key,value);
////        this.setMap(map);
//        //方式二;
//        Object put = this.getMap().put(key, value);
//        return this;
//    }
//    public Msg add(String key, List<Department> value){
//        Object put = this.getMap().put(key, value);
//        return this;
//    }
//
//    public Msg add(String key, String value) {
//        Object put = this.getMap().put(key, value);
//        return this;
//    }
}
